﻿using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
namespace InitAndOpt
{
    public class OptimizeClass
    {
        [CommandMethod("OptCommand")]
        public void OptCommand()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            // 这里不能是当前运行的dll
            string fileName = "D:\\Code\\ExternalLibrary\\bin\\Debug\\ExternalLibrary.dll";// Hello.dll程序集的文件名 这里不能是当前运行的dll
            try
            {
                //载入Hello.d11程序集
                ExtensionLoader.Load(fileName);
                
                //在命令行上显示信息，提示用户Hello.d11程序集已经被载入
                ed.WriteMessage("\n”+ fileName +“被载入，请输入Hello进行测试!");
            }
            catch (System.Exception ex)//捕捉程序异常
            {
                ed.WriteMessage(ex.Message);//显示异常信息
            }
            finally
            {
                ed.WriteMessage("\nfinally语句：程序执行完毕!");
            }
        }
    }
}
